package com.yc.favorite.action;

import com.google.gson.Gson;
import com.yc.favorite.mapper.TagMapper;
import com.yc.favorite.po.Tag;
import com.yc.favorite.util.MyBatisHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/allTag.s")
public class TagServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf-8");
        List<Tag> list = MyBatisHelper.execute(s -> s.getMapper(TagMapper.class).selectAll());
        String json = new Gson().toJson(list);
        resp.getWriter().append(json);
    }
}
